﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using UI.Core.Interface;

namespace UI.Core.Services
{
    public class ModuleServices : IModuleServices
    {
        private readonly IUnityContainer m_Container;

        public ModuleServices(IUnityContainer container)
        {
            m_Container = container;
        }

        public void ActivateView(string viewName)
        {
        
            var regionManager = m_Container.Resolve<IRegionManager>();
            IRegion workspaceRegion = regionManager.Regions["MainRegion"];
            var views = workspaceRegion.Views;
            foreach (var view in views)
            {
                workspaceRegion.Deactivate(view);
            }

            var viewToActivate = regionManager.Regions["MainRegion"].GetView(viewName);
            regionManager.Regions["MainRegion"].Activate(viewToActivate);
        }
    }
}

